package user

import (
	"fmt"
	"goProject/api/auth"
	"goProject/db"
	"goProject/table"
	"net/http"

	"gitee.com/ruige_fun/util/std"

	"github.com/kataras/iris/v12"
)

// profile 获取自己的资料
func profile(c iris.Context) {
	id := c.GetID()
	var u table.User
	db.MySQL.Where("`id` = ?", id).First(&u)
	var p table.Profile
	db.MySQL.Where("`id` = ?", id).Preload("Role").First(&p)
	if p.ID > 0 {
		_ = auth.Role.Set(fmt.Sprint(u.ID), int64(p.RoleID)) //更新一下该用户的权限信息
	}
	u.AdminName = ""
	c.JSON(std.NewResp(http.StatusOK, "", map[string]any{
		"user":    u,
		"profile": p,
		"ip":      c.RemoteAddr(),
	}, ""))
}
